// pages/self/suggestion/suggestion.js
const httpNet = require("../../../utils/httpUtil.js");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    textarea:'',
    phone: '',
    isclick:0,
  },
  bindFormSubmit:function(e){
    console.log(e.detail.value);
    var that = this;
    const phoneRexp = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/;
    if(that.data.isclick == 0){
      that.setData({
        isclick:1
      });
      if (e.detail.value.textarea == "" || e.detail.value.textarea.length < 5) {
        wx.showToast({
          title: '最少5字符',
          icon: 'none',
          duration: 2000
        });
        that.setData({
          isclick: 0
        });
        return;
      };
      if (e.detail.value.phone.length != 11) {
        wx.showToast({
          title: '您的手机号有误',
          icon: 'none',
          duration: 2000
        });
        that.setData({
          isclick: 0
        });
        return;
      };
      if (!phoneRexp.test(e.detail.value.phone)) {
        wx.showToast({
          title: '手机号格式有误',
          icon: 'none',
          duration: 2000
        });
        that.setData({
          isclick: 0
        });
        return;
      };
      httpNet.reqPost('sys/addSysFeedBack.do', { userId: this.data.uid, content: e.detail.value.textarea, mobilePhone: e.detail.value.phone, type: 2 }, function (res) {
        console.log(res)
        if (res.resultCode == 1000) {
          wx.showToast({
            title: '反馈成功',
            icon: 'success',
            duration: 2000
          });
          that.setData({
            textarea: '',
            phone: '',
            isclick:0
          });
        } else {
          that.setData({
            isclick: 0
          });
          wx.showToast({
            title: '反馈失败',
            icon: 'none',
            duration: 2000
          });
        }
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 获取用户id
    var that = this;
    var value = wx.getStorageSync('uid')
    if (value) {
      // Do something with return value
      console.log(value)
      that.setData({
        uid: value
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})